package com.haixiaoke.saas.enterprise.lock.controller;

import com.haixiaoke.saas.common.annotation.Log;
import com.haixiaoke.saas.common.core.domain.AjaxResult;
import com.haixiaoke.saas.common.core.page.TableDataInfo;
import com.haixiaoke.saas.common.enums.BusinessType;
import com.haixiaoke.saas.common.utils.poi.ExcelUtil;
import com.haixiaoke.saas.lock.domain.LockFace;
import com.haixiaoke.saas.lock.service.ILockFaceService;
import com.haixiaoke.saas.system.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;


/**
 * 锁人脸信息Controller
 *
 * @author qixi
 * @date 2024-07-26
 */
@RestController
@RequestMapping("/enterprise/lock/lockFace")
public class EnterpriseLockFaceController extends BaseController {
    @Autowired
    private ILockFaceService lockFaceService;

    /**
     * 查询锁人脸信息列表
     */
    @PreAuthorize("@ss.hasPermi('lock:lockFace:list')")
    @GetMapping("/list")
    public TableDataInfo list(LockFace lockFace) {
        startPage();
        List<LockFace> list = lockFaceService.selectLockFaceList(lockFace);
        return getDataTable(list);
    }

    /**
     * 导出锁人脸信息列表
     */
    @PreAuthorize("@ss.hasPermi('lock:lockFace:export')")
    @Log(title = "锁人脸信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LockFace lockFace) {
        List<LockFace> list = lockFaceService.selectLockFaceList(lockFace);
        ExcelUtil<LockFace> util = new ExcelUtil<LockFace>(LockFace.class);
        util.exportExcel(response, list, "锁人脸信息数据");
    }

    /**
     * 获取锁人脸信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('lock:lockFace:query')")
    @GetMapping(value = "/{faceId}")
    public AjaxResult getInfo(@PathVariable("faceId") Long faceId) {
        return success(lockFaceService.selectLockFaceByFaceId(faceId));
    }

    /**
     * 新增锁人脸信息
     */
    @PreAuthorize("@ss.hasPermi('lock:lockFace:add')")
    @Log(title = "锁人脸信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LockFace lockFace) {
        return toAjax(lockFaceService.insertLockFace(lockFace));
    }

    /**
     * 修改锁人脸信息
     */
    @PreAuthorize("@ss.hasPermi('lock:lockFace:edit')")
    @Log(title = "锁人脸信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LockFace lockFace) {
        return toAjax(lockFaceService.updateLockFace(lockFace));
    }

    /**
     * 删除锁人脸信息
     */
    @PreAuthorize("@ss.hasPermi('lock:lockFace:remove')")
    @Log(title = "锁人脸信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{faceIds}")
    public AjaxResult remove(@PathVariable Long[] faceIds) {
        return toAjax(lockFaceService.deleteLockFaceByFaceIds(faceIds));
    }
}
